import matplotlib.pyplot as plt
import numpy as np

# 数据
years = ['2022', '2023']
operating_revenue = [113.38, 124.76]  # 营业总收入（单位：亿元）
net_profit = [3.295, 1.735]  # 净利润（单位：亿元）

# 设置柱状图的颜色
colors = ['skyblue', 'lightgreen']

# 创建柱状图
fig, ax1 = plt.subplots()

# 柱状图
bars = plt.bar(years, operating_revenue, color=colors[0], label='Operating Revenue')

# 折线图
line, = ax1.plot(years, net_profit, color=colors[1], marker='o', label='Net Profit')

# 在柱体上显示数据
for bar in bars:
    yval = bar.get_height()
    plt.text(bar.get_x() + bar.get_width()/2.0, yval, round(yval, 2), ha='center', va='bottom')

# 设置标题和轴标签
plt.title('Operating Revenue and Net Profit Comparison (2022-2023)')
plt.xlabel('Year')
plt.ylabel('Amount (Unit: Billion Yuan)')

# 创建第二个y轴
ax2 = ax1.twinx()

# 折线图的y轴
ax2.plot(years, net_profit, color=colors[1], marker='o', label='Net Profit')

# 在折线图上显示数据
for i, txt in enumerate(net_profit):
    ax2.annotate(txt, (years[i], net_profit[i]), textcoords="offset points", xytext=(0,10), ha='center')

ax2.set_ylabel('Net Profit (Unit: Billion Yuan)')

# 图例
lines, labels = ax1.get_legend_handles_labels()
lines2, labels2 = ax2.get_legend_handles_labels()
ax2.legend(lines + lines2, labels + labels2, loc='upper left')

# 显示图形
plt.show()